﻿using UnityEngine;
using System.Collections;

public class BackGroundParticleScript : MonoBehaviour 
{
    public static BackGroundParticleScript instance;
    bool isOn = false;

    void Awake()
    {
        instance = this;
        transform.FindChild("ParticleSystem").GetComponent<ParticleSystem>().Stop();
        transform.FindChild("ParticleSystem").GetComponent<ParticleSystem>().Clear();
    }

    void Start()
    {

    }

    void Update()
    {

    }

    public void StartAt(Vector3 position)
    {
        if (!isOn)
        {
            transform.position = new Vector3(position.x, position.y, position.z + 0.5f);
            transform.FindChild("ParticleSystem").GetComponent<ParticleSystem>().Play();
        }
        isOn = true;
    }

    public void Stop()
    {
        isOn = false;
        transform.FindChild("ParticleSystem").GetComponent<ParticleSystem>().Stop();
        transform.FindChild("ParticleSystem").GetComponent<ParticleSystem>().Clear();
    }

    public void SetColor(Color color)
    {
        Color newColor = new Color(color.r, color.g, color.b, transform.FindChild("ParticleSystem").renderer.material.color.a);
        transform.FindChild("ParticleSystem").renderer.material.SetColor("_Color", newColor);
    }
}
